const { login } = require('../controller/user')
const { SuccessModel, ErrorModel } = require("../model/resModel")



const userHandleRouther = (req, res) => {
    //登录
    if (req.method === "GET" && req.path === "/api/user/login") {
        // const usersname = req.query.usersname
        // const password = req.query.password
        const { username, password } = req.query
        const result = login(username, password)
        return result.then((data) => {
            if (data.username) {
                res.setHeader('Set-Cookie', `username=${data.username};path=/; httpOnly;expires=${getCookieExpires()}`)

                return new SuccessModel("已经登录")
            }
            return new ErrorModel("还没有登录")
        });
    }
}
module.exports = userHandleRouther